class Api::V1::ChatMessagesController < Api::V1::BaseController
  skip_before_action :authenticate_request!, only: [:index, :create]

  def index
    @chat_messages = ChatMessage.where(chat_window_id: params[:chat_window_id]).order("created_at ASC").page(params[:page]).per(params[:per])
  end

  def create
    @chat_message = ChatMessage.new(
      chat_window_id: params[:chat_window_id],
      messageable_id: params[:messageable_id],
      messageable_type: params[:messageable_type],
      content: params[:content]
    )
    if @chat_message.save
    else
      render json: { result: false, message: '发送失败.' }, status: :ok
    end
  end
end
